//添加
$(function(){
	$.ajax({
		url:"../json/list.json",
		dataType:"json",
		async:false,
		success:function(data){
			var mag = data.data;
			var str = "";
			var o = -1;
			//for(var i in mag){
			var o =	getCookie("dataid");
			//alert(o)
				
				str += '<div class="l left"><div class="divimg"><div class="proshow"><img class="clone" src="../img/list/'+o+'.jpg"/><div class="fangdajing"><img src="../img/list/'+o+'.jpg"/></div><div class="fdj"></div><div class="zhezhaoceng"></div></div><div class="prophoto"><div class="ulwai"><a class="prev" href="javascript:;"><img src="../img/details/prev.jpg"/></a><a class="next" href="javascript:;"><img src="../img/details/next.jpg"/></a><ul><li class="l"><img src="../img/list/'+o+'.jpg" /></li><li class="l"><img src="../img/details/1.jpg" /></li><li class="l"><img src="../img/details/2.jpg" /></li><li class="l"><img src="../img/details/3.jpg" /></li><li class="l"><img src="../img/details/4.jpg" /></li><li class="l"><img src="../img/details/5.jpg" /></li><li class="l"><img src="../img/details/6.jpg" /></li></ul></div></div></div><div class="scsp"><p class="l spbh">商品编号：20-997-6727</p><div class="l sclj"><a class="l sc" href="javascript:;">收藏</a><a class="l weixin" href="javascript:;"><p class="l weixintiao"><img src="../img/details/weixintiao.jpg"/></p></a><a class="l lianjie" href="javascript:;"><p class="l lianjietiao"><img src="../img/details/lianjietiao.jpg"/></p></a></div></div></div><div class="r right"><h1>'+mag[o].atext+'</h1><div class="place"><p class="YTplace"><span>银泰价：</span><strong>￥'+mag[o].price+'.<em>00</em></strong><em class="sale">'+mag[o].sale+'</em></p><div class="markplace"><div class="markplacenum">参考价：<span>￥499.<em>00</em></span></div></div></div><div class="protime"><div><span class="l yellow"><strong >特卖</strong><em></em></span>数量有限，先到先得<p type="Bargain" end="2016/8/30 8:00:00" start="2016/8/23 10:00:00" class=" p-timeout"></p></div><div><span class="yellow"><strong>特卖</strong><em></em></span><a href="http://www.yintai.com/product/list-1.html?channelid=1100101&promotionid=83174" target="_blank"> 新百伦	满299减30，可累计</a></div></div><div class="prochange"><p class="tishi">请选择您要的商品信息<b>X</b></p><div class="prosize"><dl class="color"><dt class="l"><span>选择颜色：</span></dt><dd class="l"><div class="changeone"><b></b><a title="灰色" href="Javascript:void(0);" ><img src="../img/list/'+o+'.jpg"  /><span>灰色</span></a></div></dd></dl><dl class="size"><dt class="l"><span>选择尺码：</span></dt><dd class="l"><div class="sizeIntro"><a class="cmsm" title="侧尺码说明" href="javascript:;"><span>尺码说明</span></a></div><div class="item"><b></b><a title="35" href="javascript:void(0);"><span>35</span></a></div><div class="item"><b></b><a title="36" href="javascript:void(0);"><span>36</span></a></div><div class="item"><b></b><a title="36.5" href="javascript:void(0);"><span>36.5</span></a></div><div class="item"><b></b><a title="37" href="javascript:void(0);"><span>37</span></a></div><div class="item"><b></b><a title="37.5" href="javascript:void(0);"><span>37.5</span></a></div><div class="item"><b></b><a title="38" href="javascript:void(0);"><span>38</span></a></div><div class="item"><b></b><a title="39" href="javascript:void(0);"><span>39</span></a></div><div class="item"><b></b><a title="40" href="javascript:void(0);"><span>40</span></a></div></dd></dl><div class="probuy"><div class="l buynum"><div class="l fl"><input type="text" maxlength="2" id="buyNum" step="1" max="99" min="1" value="1" /></div><div class="l fl two"><a class="l p-num-add" id="addNum" href="javascript:;"></a><a class="l p-num-red" id="reduceNum" href="javascript:;"></a></div></div><div class="l addshopcar"><button title="立即购买" class="buynow buyit"></button><button id="Y_incart" class="incart" title="加入购物车"></button></div></div></div></div><div class="serviceInfo"><dl class="service"><dt class="l">服务承诺：</dt><dd class="l"><span>正品保障</span><span>支持无理由退换货</span><span>免运费</span></dd></dl></div></div></div>';
			//}
			$("#content .bx .shopper .procon").append(str);
			
		}
	})

})







































//判断登录
$(function(){
	var login_btn = $("#yonghuming");
	var register_btn = $("#tuichu");

	if(getCookie("true")=="true"){
		login_btn.text("您好！"+getCookie("user"));
		//login_btn.attr("href","javascript:;");
		register_btn.text("退出").css("color","#EE0011");
		register_btn.attr("href","javascript:;");	
	}else{
		login_btn.text("登录").css("color","#EE0011").attr("href","denglu.html");
		register_btn.text("注册").css("color","#EE0011").attr("href","zhuce.html");	
	}
	register_btn.click(function(){
		setCookie("true",false,setCookieDate(7),"/");
		login_btn.text("登录").css("color","#EE0011").attr("href","javascript:;");
		register_btn.text("注册").css("color","#EE0011").attr("href","javascript:;");
		login_btn.click(function(){
			window.location.href = "denglu.html";
		});
		register_btn.click(function(){
			window.location.href = "zhuce.html";
		})
	})
	
	
})
//放大镜加选取换图
$(function(){
	
	var $picL = $("#content .bx .shopper .procon .left .divimg .proshow .fangdajing img");
	var $fdj = $("#content .bx .shopper .procon .left .divimg .proshow .fdj");
	var $mark = $("#content .bx .shopper .procon .left .divimg .proshow .zhezhaoceng");
	$mark.hover(function(){
		$fdj.css("display","block");
		$picL.parent().css("display","block");
	},function(){
		$fdj.css("display","none");
		$picL.parent().css("display","none");
	})

	$("#content .bx .shopper .procon .left .divimg .proshow").on("mousemove",".zhezhaoceng",function(evt){
		var e = evt || window.event;
		var L = e.offsetX;
		var T = e.offsetY;
		var oL = L - 60;
		var oT = T - 75;
		if(L < 60){
			oL = 0
		}else if(L > 240){
			oL = 180;
		}
		if(T < 75){
			oT = 0
		}else if(T > 325 ){
			oT = 250;
		}
		$fdj.css({"left":oL,"top":oT});
		$picL.css({"margin-left":(-oL/300)*750,"margin-top":(-oT/400)*1000})
	})
	var $li = $("#content .bx .shopper .procon .left .divimg .prophoto .ulwai ul li");
	$li.mouseover(function(){
		var str = $(this).find("img").attr("src");	
		$("#content .bx .shopper .procon .left .divimg .proshow img").attr("src",str);
	})		
})
//展示产品的箭头选取
$(function(){
	$("#content .bx .shopper .procon .left .divimg .prophoto .ulwai").on("click",".prev",function(){
		var addleft = Number($(this).next().next().css("margin-left").split("px")[0]) + 72;
		if(addleft > 0){
			addleft = -432;
		}else if((-72 < addleft) && (addleft < -144)){
			addleft = 0;
		}else if((-432 < addleft) && (addleft < -360)){
			addleft = -360;
		}else if((-360 < addleft) && (addleft < -288)){
			addleft = -288;
		}else if((-288 < addleft) && (addleft < -216)){
			addleft = -216;
		}else if((-216 < addleft) && (addleft < -144)){
			addleft = -144;
		}else if((-144 < addleft) && (addleft < -72)){
			addleft = -72;
		}
		$(this).next().next().stop(true).animate({"margin-left":addleft + "px"},300)
	})
	$("#content .bx .shopper .procon .left .divimg .prophoto .ulwai").on("click",".next",function(){
		var addleft = Number($(this).next().css("margin-left").split("px")[0]) - 72;
		if(addleft <= -504){
			addleft = 0;
		}else if((-504 < addleft) && (addleft < -432)){
			addleft = -432;
		}else if((-432 < addleft) && (addleft < -360)){
			addleft = -360;
		}else if((-360 < addleft) && (addleft < -288)){
			addleft = -288;
		}else if((-288 < addleft) && (addleft < -216)){
			addleft = -216;
		}else if((-216 < addleft) && (addleft < -144)){
			addleft = -144;
		}else if((-144 < addleft) && (addleft < -72)){
			addleft = -72;
		}
		$(this).next().stop(true).animate({"margin-left":addleft + "px"},300)
	})	
	
})
//收藏 微信 手机支付
$(function(){
	$("#content .bx .shopper .procon .left .scsp .sclj .sc").mouseover(function(){
		$(this).css("border-color","#E0034F")
	})
	$("#content .bx .shopper .procon .left .scsp .sclj .sc").mouseout(function(){
		$(this).css("border-color","#fff")
	})
	$("#content .bx .shopper .procon .left .scsp .sclj .weixin").mouseover(function(){
		$(this).css("border-color","#eee")
		$(this).children("p").css("display","block")
	})
	$("#content .bx .shopper .procon .left .scsp .sclj .weixin").mouseout(function(){
		$(this).css("border-color","#fff")
		$(this).children("p").css("display","none")
	})
	$("#content .bx .shopper .procon .left .scsp .sclj .lianjie").mouseover(function(){
		$(this).css("border-color","#eee")
		$(this).children("p").css("display","block")
	})
	$("#content .bx .shopper .procon .left .scsp .sclj .lianjie").mouseout(function(){
		$(this).css("border-color","#fff")
		$(this).children("p").css("display","none")
	})
})


//倒计时
$(function(){
	var now2 = new Date(2016,7,31,10,00,00);	
	var long2 = now2.getTime();
	
	
	setInterval(function () {
		var now1 = new Date();
		var long1 = now1.getTime();
		var long3 = long2 - long1;
		var	date2 = Math.floor(long3 /3600000 /24);
		var	hour2 = Math.floor((long3 % (3600000 *24) / 3600000));
		var	minute2 = Math.floor(((long3 % (3600000 *24) % 3600000)/60000));
		var	second2 = Math.floor((((long3 % (3600000 *24) % 3600000)%60000) / 1000));
		var millisecond1 = now1.getMilliseconds();
		var endtime = "，此价格还有" + date2 + "天" + hour2 + "时" + minute2 + "分" +second2 + "秒" + Math.floor((millisecond1 )/100) ;
		$(".p-timeout").html(endtime);
	},100)
})

//点击选取商品
$(function(){
	var xuanqu = 0;
	$("#content .bx .shopper .procon .right .prochange .prosize dl.size dd .item").on("click","a",function(){
		$(this).css("border-color","#E0034F").parent().siblings().children("a").css("border-color","#ccc")
		xuanqu = 1;
		 size = $(this).children("span").html();
		//alert(size)
		$(this).prev().css("background-position-y","-240px").parent().siblings().children("b").css("background-position-y","-250px")
	})
	
//添加数量
	$("#content .bx .shopper .procon .right .prochange .prosize .probuy .buynum .fl ").on("click","a.p-num-add",function(){
		var num =Number($(this).parent().prev().children("input").val()) + 1;
		if(num > 99){
			num = 99;
			alert("已达到最大数量了哦 亲！")
		}
		$(this).parent().prev().children("input").val(num);
	})
	$("#content .bx .shopper .procon .right .prochange .prosize .probuy .buynum .fl ").on("click","a.p-num-red",function(){
		var num =Number($(this).parent().prev().children("input").val()) - 1;
		if(num < 1){
			num = 1;
			alert("最少为一件哦 亲！")
		}
		$(this).parent().prev().children("input").val(num);
	})
	
	
	
	
	
	
	//外框 立即购买!!!

	$("#content .bx .shopper .procon .right .prochange .prosize .probuy .addshopcar button.buynow").click(function(){
		var Num = $("#content .bx .shopper .procon .right .prochange .prosize .probuy .buynum .fl input").val();
		var money = Number($("#content .bx .shopper .procon .right .place p.YTplace strong").html().substr(1,3));
		if(xuanqu == 0){
			$("#content .bx .shopper .procon .right .prochange").css("border-color","#f00")
			$("#content .bx .shopper .procon .right .prochange p.tishi").css("display","block")
		}
		if($("#yonghuming").html() == "登录"){
			if(confirm("是否立即登录 亲？")){
				window.location.href="denglu.html";
			}
		}else{
			if(xuanqu == 0){
				$("#content .bx .shopper .procon .right .prochange").css("border-color","#f00")
				$("#content .bx .shopper .procon .right .prochange p.tishi").css("display","block")
			}else {
				var dataid = getCookie("dataid");
				 Num = Number($("#content .bx .shopper .procon .right .prochange .prosize .probuy .buynum .fl input").val());
				money = Number($("#content .bx .shopper .procon .right .place p.YTplace strong").html().substr(1,3));
				var color = $("#content .bx .shopper .procon .right .prochange .prosize dl.color dd .changeone a span").html();
				if(getCookie(dataid)){
					var old = Number(getCookie(dataid+"n"));
					//alert(old)
					//alert(1)
					var nowNum = Number(old + Num);
					setCookie(dataid,dataid,setCookieDate(7));
					setCookie(dataid+"b",dataid,setCookieDate(7));
					setCookie(dataid+"n",nowNum,setCookieDate(7));
					setCookie(dataid+"c",color,setCookieDate(7));
					setCookie(dataid+"s",size,setCookieDate(7));
					
				}else{
					setCookie(dataid,dataid,setCookieDate(7));
					setCookie(dataid+"b",dataid,setCookieDate(7));
					setCookie(dataid+"n",Num,setCookieDate(7));
					setCookie(dataid+"c",color,setCookieDate(7));
					setCookie(dataid+"s",size,setCookieDate(7));
				}
				
						window.location.href="dingdan.html";

			}
			
		}
	})
	$("#content .bx .shopper .procon .right .prochange p.tishi b").click(function(){
		$("#content .bx .shopper .procon .right .prochange").css("border-color","#fff")
		$("#content .bx .shopper .procon .right .prochange p.tishi").css("display","none")
	})

//加入购物车
	$("#Y_incart").click(function(){
		var dataid = getCookie("dataid");
		 Num = Number($("#content .bx .shopper .procon .right .prochange .prosize .probuy .buynum .fl input").val());
		money = Number($("#content .bx .shopper .procon .right .place p.YTplace strong").html().substr(1,3));
		var color = $("#content .bx .shopper .procon .right .prochange .prosize dl.color dd .changeone a span").html();
		
		if(xuanqu == 0){
			$("#content .bx .shopper .procon .right .prochange").css("border-color","#f00")
			$("#content .bx .shopper .procon .right .prochange p.tishi").css("display","block")
		}else {
			var str = "你已经成功加入"+Num+"件商品，总计"+Num*money+"元";
			
			if(getCookie(dataid)){
				var old = Number(getCookie(dataid+"n"));
				//alert(old)
				//alert(1)
				var nowNum = Number(old + Num);
				setCookie(dataid,dataid,setCookieDate(7));
				setCookie(dataid+"n",nowNum,setCookieDate(7));
				setCookie(dataid+"c",color,setCookieDate(7));
				setCookie(dataid+"s",size,setCookieDate(7));
				
				
				
			}else{
				setCookie(dataid,dataid,setCookieDate(7));
				setCookie(dataid+"n",Num,setCookieDate(7));
				setCookie(dataid+"c",color,setCookieDate(7));
				setCookie(dataid+"s",size,setCookieDate(7));
			}
		
			//飞行动画
			$(".clone").clone().css({"position":"absolute","z-index":"10000","right":"700px","top":"210px","width":"480px"}).appendTo($("body")).animate({"right":"100px","width":"20px","top":"160px","opacity":"0","filter":"alpha(opacity=0)"},1000,function(){
						$(this).detach();
						window.location.reload();
						if(confirm("是否查看购物车？")){
							window.location.href="shopcar.html";
						}
					});		
				//alert(str);
				
			}
		
	})	





})




//下面详情切换
$(function(){
	$("#content .bx .xiangqing .left .toplook ul li").eq(0).css("background-color","#b7ab91")
	$("#content .bx .xiangqing .left .toplook ul").on("click","li",function(){
		$(this).css("background-color","#b7ab91").siblings().css("background-color","#999")
		var zhege = $(this).index();
		$(this).parent().parent().next().children("ul").children().eq(zhege).show().siblings().hide()
	})
	
	$(window).scroll(function(){
		var Topnum = $(this).scrollTop();
		//document.title = Topnum;
		if(Topnum >= 873 ){
			$("#content .bx .xiangqing .left .toplook").css({"position":"fixed","left":"37px","top":"0px"})
			$("#hddb").css("display","block")
		}else if(Topnum < 873 ){
			$("#content .bx .xiangqing .left .toplook").css({"position":"absolute","left":"0px","top":"-30px"})
			$("#hddb").css("display","none")
		}
		
	})				
	
})
//右侧换一批
$(function(){
	var i = 0;
	$("#content .bx .xiangqing div.right li p.topp").on("click",".huanyipi",function(){
		
		if(i == 0){
			$(this).parent().next().children("li").eq(0).children("dl").children("dt").children("img").attr("src","../img/details/hyp0.jpg")
			$(this).parent().next().children("li").eq(1).children("dl").children("dt").children("img").attr("src","../img/details/hyp1.jpg")
			$(this).parent().next().children("li").eq(2).children("dl").children("dt").children("img").attr("src","../img/details/hyp2.jpg")
			$(this).parent().next().children("li").eq(3).children("dl").children("dt").children("img").attr("src","../img/details/hyp3.jpg")
			$(this).parent().next().children("li").eq(4).children("dl").children("dt").children("img").attr("src","../img/details/hyp4.jpg")
			i++;
		}else if( i == 1){
			$(this).parent().next().children("li").eq(0).children("dl").children("dt").children("img").attr("src","../img/details/hyp5.jpg")
			$(this).parent().next().children("li").eq(1).children("dl").children("dt").children("img").attr("src","../img/details/hyp6.jpg")
			$(this).parent().next().children("li").eq(2).children("dl").children("dt").children("img").attr("src","../img/details/hyp7.jpg")
			$(this).parent().next().children("li").eq(3).children("dl").children("dt").children("img").attr("src","../img/details/hyp8.jpg")
			$(this).parent().next().children("li").eq(4).children("dl").children("dt").children("img").attr("src","../img/details/hyp9.jpg")
			i++;
		}else{
			
			$(this).parent().next().children("li").eq(0).children("dl").children("dt").children("img").attr("src","../img/details/hyp10.jpg")
			$(this).parent().next().children("li").eq(1).children("dl").children("dt").children("img").attr("src","../img/details/hyp11.jpg")
			$(this).parent().next().children("li").eq(2).children("dl").children("dt").children("img").attr("src","../img/details/hyp12.jpg")
			$(this).parent().next().children("li").eq(3).children("dl").children("dt").children("img").attr("src","../img/details/hyp13.jpg")
			$(this).parent().next().children("li").eq(4).children("dl").children("dt").children("img").attr("src","../img/details/hyp14.jpg")
			i = i-2;
		}
//		$(this).parent().next().children("li").children("dl").children("dt").children("img").attr("src","../img/details/hyp0.jpg")
	})
})



//回到顶部
$(function(){
	$("#hddb").on("click","a",function(){
		$("html,body").stop(true).animate({"scrollTop":"0"},300);
	})
})


















































